package com.aaa.service.sds.impl;

import cn.hutool.core.util.ObjectUtil;
import com.aaa.aspect.InsertAnn;
import com.aaa.aspect.UpdateAnn;
import com.aaa.dao.sds.TestPlanSdsDao;
import com.aaa.entity.PageSortEntity;
import com.aaa.entity.sds.TestPlanSds;
import com.aaa.service.sds.TestPlanSdsService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Random;

/**
 * @author ：周文达（3220083246@qq.com）
 * @date ：Created in 2022/8/31 10:09
 * @description：
 * @modified By：
 * @version:
 */
@Service("PlanSdsService")
public class TestPlanSdsServiceImpl implements TestPlanSdsService {
    @Autowired
    TestPlanSdsDao testPlanSdsDao;

    //查询所有
    @Override
    public List<TestPlanSds> queryAll(PageSortEntity pageSortEntity, TestPlanSds testPlanSds) {
        PageHelper.startPage(pageSortEntity.getPage(), pageSortEntity.getLimit(), pageSortEntity.getOrderString());
        List<TestPlanSds> ppp = testPlanSdsDao.queryAll(testPlanSds);
        Page page = (Page) ppp;
        return page;
    }

    //插入
    @InsertAnn
    @Override
    public boolean insert(TestPlanSds testPlanSds) {
        return testPlanSdsDao.insert(testPlanSds);
    }

    //删除
    @Override
    public boolean delete(String id) {
        return testPlanSdsDao.delete(id);
    }

    //修改
    @UpdateAnn
    @Override
    public boolean update(TestPlanSds testPlanSds) {
        return testPlanSdsDao.update(testPlanSds);
    }

    @Override
    public long queryByTestCode() {
        long random=0;
        random=this.random();
        while (testPlanSdsDao.queryByTestCode(random).size()>0){
            random=this.random();
        }
        return random;
    }

    //名字唯一性校验
    @Override
    public boolean repetitionName(TestPlanSds testPlanSds) {
        TestPlanSds pp = testPlanSdsDao.repetitionName(testPlanSds);
        if (ObjectUtil.isEmpty(pp) || pp.getId().equals(testPlanSds.getId())) {
            return true;
        } else {
            return false;
        }
    }


    public long random(){
        long flag=0;
        for (int i = 0; i <= 100; i++)
        {
            flag = new Random().nextInt(999999);
            if (flag < 100000)
            {
                flag += 100000;
            }

        }
        return flag;
    }
}